package org.fuxia.im.gui;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class MyTableCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 1L;

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		
		if(value!=null && value.getClass().isAssignableFrom(ImageIcon.class)){
			JButton button = new JButton() ;
			ImageIcon icon = (ImageIcon)value ;
			button.setOpaque(false);
			button.setSize(icon.getIconWidth(), icon.getIconHeight()) ;
			button.setIcon(icon) ;
			button.setBorder(null);
			button.setContentAreaFilled(false);
			return button ;
		}else {
			super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
			return this ;
		}
		
	}

}
